package com.ruoyi.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.service.FoodCondimentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.FoodCondiment;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 调料Controller
 *
 * @author xian_pei
 * @date 2024-06-10
 */
@RestController
@RequestMapping("/condiment/condiment")
public class FoodCondimentController extends BaseController
{
    @Autowired
    private FoodCondimentService foodCondimentService;

    /**
     * 查询调料列表
     */
    @PreAuthorize("@ss.hasPermi('condiment:condiment:list')")
    @GetMapping("/list")
    public TableDataInfo list(FoodCondiment foodCondiment)
    {
        startPage();
        List<FoodCondiment> list = foodCondimentService.selectFoodCondimentList(foodCondiment);
        return getDataTable(list);
    }

    /**
     * 导出调料列表
     */
    @PreAuthorize("@ss.hasPermi('condiment:condiment:export')")
    @Log(title = "调料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FoodCondiment foodCondiment)
    {
        List<FoodCondiment> list = foodCondimentService.selectFoodCondimentList(foodCondiment);
        ExcelUtil<FoodCondiment> util = new ExcelUtil<FoodCondiment>(FoodCondiment.class);
        util.exportExcel(response, list, "调料数据");
    }

    /**
     * 获取调料详细信息
     */
    @PreAuthorize("@ss.hasPermi('condiment:condiment:query')")
    @GetMapping(value = "/{condimentId}")
    public AjaxResult getInfo(@PathVariable("condimentId") Long condimentId)
    {
        return success(foodCondimentService.selectFoodCondimentByCondimentId(condimentId));
    }

    /**
     * 新增调料
     */
    @PreAuthorize("@ss.hasPermi('condiment:condiment:add')")
    @Log(title = "调料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FoodCondiment foodCondiment)
    {
        return toAjax(foodCondimentService.insertFoodCondiment(foodCondiment));
    }

    /**
     * 修改调料
     */
    @PreAuthorize("@ss.hasPermi('condiment:condiment:edit')")
    @Log(title = "调料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FoodCondiment foodCondiment)
    {
        return toAjax(foodCondimentService.updateFoodCondiment(foodCondiment));
    }

    /**
     * 删除调料
     */
    @PreAuthorize("@ss.hasPermi('condiment:condiment:remove')")
    @Log(title = "调料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{condimentIds}")
    public AjaxResult remove(@PathVariable Long[] condimentIds)
    {
        return toAjax(foodCondimentService.deleteFoodCondimentByCondimentIds(condimentIds));
    }
}
